package com.talkweb.osmharmony.views.drawing;

import com.talkweb.osmharmony.tileprovider.MapTileProviderBase;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;

/**
 * Custom-made {@link EventHandler} for {@link MapSnapshot}
 *
 * @author Fabrice Fontaine
 * @since 6.1.0
 */
public class MapSnapshotHandler extends EventHandler {

    private MapSnapshot mMapSnapshot;

    public MapSnapshotHandler(final MapSnapshot pMapSnapshot) {
        super(EventRunner.getMainEventRunner());
        mMapSnapshot = pMapSnapshot;
    }

    @Override
    protected void processEvent(InnerEvent event) {
        super.processEvent(event);
        switch (event.eventId) {
            case MapTileProviderBase.MAPTILE_SUCCESS_ID:
                final MapSnapshot mapSnapshot = mMapSnapshot;
                if (mapSnapshot != null) { // in case it was destroyed just before
                    mapSnapshot.refreshASAP();
                }
                break;
        }
    }

    public void destroy() {
        mMapSnapshot = null;
    }
}
